package com.taxigang.client.uibinder_mobile;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasAllFocusHandlers;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.jquery.mobile.ui.Button;
import com.google.gwt.jquery.mobile.ui.FieldContain;
import com.google.gwt.jquery.mobile.ui.TextBox;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBoxBase;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.Authenication.Provider;
import com.taxigang.client.Session;
import com.taxigang.client.TaxiGangHandler;
import com.taxigang.client.TaxigangMode;
import com.taxigang.client.facebook.ConnectState;
import com.taxigang.client.facebook.FacebookApi;
import com.taxigang.client.micro.Hideable;
import com.taxigang.client.micro.TaxiGangCreator;
import com.taxigang.client.ui.ButtonType;
import com.taxigang.client.ui.map.Geolocator;
import com.taxigang.client.ui.map.JoinView;
import com.taxigang.client.ui.map.MapView;
import com.taxigang.client.ui.map.MobileNavigatorManager;
import com.taxigang.client.ui.map.ProcessingDialog;
import com.taxigang.client.ui.map.SearchView;
import com.taxigang.client.uibinder.TaxiCompanyDialog;
import com.taxigang.client.uibinder.TaxiGangPresenter;
import com.taxigang.client.uibinder.TaxiGangRoute;
import com.taxigang.client.uibinder.TaxiGangRoute.CreateMode;
import com.taxigang.shared.ChitInfo;
import com.taxigang.shared.LoginInfo;
import com.taxigang.shared.TaxiCompanyInfo;
import com.taxigang.shared.TaxiGangInfo;

public class TaxiGangMobile extends Composite implements SearchView, MapView, JoinView{

	private static TaxiGangMobileUiBinder uiBinder = GWT
	.create(TaxiGangMobileUiBinder.class);

	interface TaxiGangMobileUiBinder extends UiBinder<Widget, TaxiGangMobile> {
	}

	private HashMap<PanelType,Panel> taxiGangPanels = new HashMap<PanelType,Panel>();

	//private NavigatorWidget mapViewWidget;

	private PanelType panelToShowAtShowLogin = PanelType.SEARCH;

	//TaxiGangRoute taxiGangRoute;
	public TaxiGangMobile() {

		initWidget(uiBinder.createAndBindUi(this));
		initSearch();
		initSorry();
		initCongratulations();
		initCongratulationsJoin();
		initMobileNumber();
		initCreateStep1();
		initCreateStep2a();
		initCreateStep2b();
		initCreateStep3();
		initLogin();
		initMyTaxiGangs();
		initMessages();
		initSuggestion();
		initNewMessage();
		initOrderTaxiCompany();

		TaxiGangPresenter.getInstance().setMapView(this,this);

		taxiGangPanels.put(PanelType.SEARCH,searchPanel);
		//		taxiGangPanels.put(PanelType.FEEDBACK,feedback);
		taxiGangPanels.put(PanelType.LOGIN,loginPanel);
		taxiGangPanels.put(PanelType.CREATE_STEP1,createStep1Panel);
		taxiGangPanels.put(PanelType.CREATE_STEP2A,createStep2aPanel);
		taxiGangPanels.put(PanelType.CREATE_STEP2B,createStep2bPanel);
		taxiGangPanels.put(PanelType.CREATE_STEP3,createStep3Panel);
		taxiGangPanels.put(PanelType.SORRY,sorryPanel);
		taxiGangPanels.put(PanelType.MYTAXIGANGS,myTaxiGangsPanel);
		taxiGangPanels.put(PanelType.SUGGESTION,suggestionsPanel);
		taxiGangPanels.put(PanelType.MESSAGES,messagesPanel);
		taxiGangPanels.put(PanelType.NEW_MESSAGE,newMessagePanel);
		taxiGangPanels.put(PanelType.CONGRATULATIONS_CREATE,congratulationsPanel);
		taxiGangPanels.put(PanelType.CONGRATULATIONS_JOIN,congratulationsJoinPanel);
		taxiGangPanels.put(PanelType.JOIN,congratulationsJoinPanel);
		taxiGangPanels.put(PanelType.MOBILENUMBER,mobileNumberPanel);
		taxiGangPanels.put(PanelType.ORDERTAXICOMPANY,orderTaxiCompanyPanel);

		taxiGangPanels.put(PanelType.MAP,mapPanel);

		show(PanelType.SEARCH);

		//mapViewWidget = new NavigatorWidget(this);

		//mapViewWidget.showMapMobile(this);//TODO improve

		menuButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				TaxiGangPresenter.getInstance().myTaxiGang(true);

			}
		});
		suggestionMapButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				show(PanelType.MAP);
				int currentMyTaxiGangIndex = Session.getInstance().getCurrentSuggestionIndex();
				TaxiGangInfo[] myTaxiGangsInfoList = Session.getInstance().getTaxiGangSearchResultList();
				TaxiGangInfo taxiganginfo = myTaxiGangsInfoList[currentMyTaxiGangIndex];
				showMyTaxiGangInMap(taxiganginfo,true);
			}
		});
		myTaxiGangsMapButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				show(PanelType.MAP);
				int currentMyTaxiGangIndex = Session.getInstance().getCurrentMyTaxiGangIndex();
				TaxiGangInfo[] myTaxiGangsInfoList = Session.getInstance().getMyTaxiGangList();
				TaxiGangInfo taxiganginfo = myTaxiGangsInfoList[currentMyTaxiGangIndex];
				showMyTaxiGangInMap(taxiganginfo,true);
			}
		});
		closeMapButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				if (showingMyTaxiGangs){
					show(PanelType.MYTAXIGANGS);
				} else {
					show(PanelType.SUGGESTION);
				}
			}
		});

		taxiGangMobile = this;
		//MobileNavigatorManager.init(this);
		
		//geolocation
		if (TaxigangMode.TAXIGANG != Session.getInstance().getMode() ){

			//no partnerm && no suggestion
				Geolocator geolocation = new Geolocator();
				geolocation.runGeolocation(getSearchView(),this);
			}

	}

	boolean showingMyTaxiGangs = true;

	@UiField
	SimplePanel mapContentPanel;

	@UiField
	Button menuButton;

	@UiField
	Button suggestionMapButton;

	@UiField
	Button myTaxiGangsMapButton;

	@UiField
	Button closeMapButton;


	public SimplePanel getMapPanel(){
		return mapContentPanel;
	}
	@UiField
	Panel searchPanel;
	@UiField
	Panel sorryPanel;
	@UiField
	Panel createStep1Panel;
	@UiField
	Panel createStep2aPanel;
	@UiField
	Panel createStep2bPanel;
	@UiField
	Panel createStep3Panel;
	@UiField
	Panel loginPanel;
	@UiField
	Panel myTaxiGangsPanel;
	@UiField
	Panel messagesPanel;
	@UiField
	Panel suggestionsPanel;
	@UiField
	Panel newMessagePanel;
	@UiField
	Panel congratulationsPanel;
	@UiField
	Panel congratulationsJoinPanel;
	@UiField
	Panel mobileNumberPanel;
	@UiField
	Panel orderTaxiCompanyPanel;

	@UiField
	Panel mapPanel;

	@UiField
	Label startLabel;
	@UiField
	Label destinationLabel;

	@UiField
	Label searchHeaderLabel;

	@UiField
	Label departureLabel;

	@UiField
	ListBox listBoxDestinationTime;

	@UiField
	Button searchButton;

	@UiField
	Button createButton;


	@UiField
	SuggestBox startSuggestion;

	@UiField
	SuggestBox destinationSuggestion;



	private Map<ButtonType,Button>searchCreateButtonMap = new HashMap<ButtonType,Button>();

	private int[]timeValues = new int[24*4];

	@Override
	public HasClickHandlers getJoinButton() {
		return 	suggestionsJoinButton;
	}

	public void initSearch() {

		String style = mobileNumberTextBox.getStyleName();
		startSuggestion.getTextBox().setStyleName(style);
		startSuggestion.getTextBox().setWidth("100%");
		destinationSuggestion.getTextBox().setStyleName(style);
		destinationSuggestion.getTextBox().setWidth("100%");



		searchHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.search());
		//layoutPanel.setBorderWidth(10);
		searchButton.setText(TaxiGangCreator.taxiGangConstants.search());
		createButton.setText(TaxiGangCreator.taxiGangConstants.newTaxigang());

		//		okButtonMap.put(TextBoxType.START_CITY, okButtonStartCity);
		//		okButtonMap.put(TextBoxType.START_ADDRESS, okButtonStartAddress);
		//		okButtonMap.put(TextBoxType.DESTINATION_CITY, okButtonDestinationCity);
		//		okButtonMap.put(TextBoxType.DESTINATION_ADDRESS, okButtonDestinationAddress);

		//		for (Button button : okButtonMap.values()){
		//			button.setText("OK");
		//			//button.setVisible(false);
		//		}

		//		okButtonDepartureTime.setText("OK");
		startLabel.setText(TaxiGangCreator.taxiGangConstants.enterStart());
		destinationLabel.setText(TaxiGangCreator.taxiGangConstants.enterDestination());
		departureLabel.setText(TaxiGangCreator.taxiGangConstants.departureTime());

		searchCreateButtonMap.put(ButtonType.Create, createButton);
		searchCreateButtonMap.put(ButtonType.Search, searchButton);

		Date calendar = new Date();
		//calendar.setMinutes(calendar.getMinutes()+30);
		int nowHour = calendar.getHours();
		int nowQuarter = calendar.getMinutes()/15;
		nowQuarter++;
		if (nowQuarter >=4){
			nowQuarter = 0;
			nowHour++;
		}
		int index=0;
		boolean begin = true;
		for (int h=nowHour; h < 24+nowHour; h++){
			for (int q=0; q < 4; q++){
				if (begin){
					begin=false;
					q=nowQuarter;
				}
				boolean today = (h<24);
				int displayHour = h;
				if (!today){
					displayHour -=24;
				}
				int mins =  q*15;
				int value = displayHour*60 + mins;
				String display = displayHour+":"+mins;
				if (mins==0){
					display +="0";
				}
				if (!today){
					display += " "+TaxiGangCreator.taxiGangConstants.tomorrow();
				}
				listBoxDestinationTime.addItem(display,""+value);
				timeValues[index++]=value;
			}
		}

		setMode(SearchDisplayMode.START);

		//startCitySuggestion = new SuggestBox(new MultiWordSuggestOracle(), startCityTextBox);
		//		startAddressSuggestion = new SuggestBox(new MultiWordSuggestOracle(), startAddressTextBox);
		//		destinationCitySuggestion = new SuggestBox(new MultiWordSuggestOracle(), destinationCityTextBox);
		//		destinationAddressSuggestion = new SuggestBox(new MultiWordSuggestOracle(), destinationAddressTextBox);

//		startCityTextBox = startCitySuggestion.getTextBox();
//		startAddressTextBox = startAddressSuggestion.getTextBox();;
//		destinationCityTextBox = destinationCitySuggestion.getTextBox();;
//		destinationAddressTextBox = destinationAddressSuggestion.getTextBox();;

		//		final Map<SuggestBox,Button>suggestBoxMap = new HashMap<SuggestBox, Button>();
		//		suggestBoxMap.put(startCitySuggestion, okButtonStartCity);
		//		suggestBoxMap.put(startAddressSuggestion, okButtonStartAddress);
		//		suggestBoxMap.put(destinationCitySuggestion, okButtonDestinationCity);
		//		suggestBoxMap.put(destinationAddressSuggestion, okButtonDestinationAddress);
		//		for (final SuggestBox suggestBox : suggestBoxMap.keySet()){
		//			suggestBox.getTextBox().addFocusHandler(new FocusHandler() {
		//			
		//			@Override
		//			public void onFocus(FocusEvent event) {
		//				for (Button b: okButtonMap.values()){
		//					b.setVisible(false);
		//				}
		//				suggestBoxMap.get(suggestBox).setVisible(true);
		//				
		//			}
		//		});
		//		}

		//		startCityTextBox.addFocusHandler(new FocusHandler() {
		//			
		//			@Override
		//			public void onFocus(FocusEvent event) {
		//				DomEvent.
		//				if (event.getType().equals(obj))
		//				Window.alert("focus");
		//				
		//			}
		//		});
		//		startCityTextBox.addKeyPressHandler(new KeyPressHandler() {
		//
		//			@Override
		//			public void onKeyPress(KeyPressEvent event) {
		//				if (event.getCharCode()==13){
		//					TaxiGangPresenter.getInstance().fireOK(TextBoxType.START_CITY);
		//				}
		//
		//			}
		//		});
		//		startAddressTextBox.addKeyPressHandler(new KeyPressHandler() {
		//
		//			@Override
		//			public void onKeyPress(KeyPressEvent event) {
		//				if (event.getCharCode()==13){
		//					TaxiGangPresenter.getInstance().fireOK(TextBoxType.START_ADDRESS);
		//				}
		//
		//			}
		//		});
		//		destinationCityTextBox.addKeyPressHandler(new KeyPressHandler() {
		//
		//			@Override
		//			public void onKeyPress(KeyPressEvent event) {
		//				if (event.getCharCode()==13){
		//					TaxiGangPresenter.getInstance().fireOK(TextBoxType.DESTINATION_CITY);
		//				}
		//
		//			}
		//		});
		//		destinationCityTextBox.addKeyPressHandler(new KeyPressHandler() {
		//
		//			@Override
		//			public void onKeyPress(KeyPressEvent event) {
		//				if (event.getCharCode()==13){
		//					TaxiGangPresenter.getInstance().fireOK(TextBoxType.DESTINATION_ADDRESS);
		//				}
		//
		//			}
		//		});
		//		
		//		destinationAddressTextBox.addKeyPressHandler(new KeyPressHandler() {
		//
		//			@Override
		//			public void onKeyPress(KeyPressEvent event) {
		//				if (event.getCharCode()==13){
		//					TaxiGangPresenter.getInstance().fireOK(TextBoxType.DESTINATION_ADDRESS);
		//				}
		//
		//			}
		//		});

	}

	@Override
	public Hideable getHideable() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public HasText getTextBoxText(MapView.TextBoxType tbt){
		HasText tb = null;
		switch (tbt){
		case START: 
			tb = startSuggestion;  
			break;
		case DESTINATION: tb = destinationSuggestion;  break;

		}
		return tb;
	}

	@Override
	public SuggestBox getSuggestBox(TextBoxType tbt) {
		SuggestBox sb = null;
		switch (tbt){
		case START: 
			sb = startSuggestion;  
			break;
		case DESTINATION: sb = destinationSuggestion;  break;

		}
		return sb;
	}

	@Override
	public HasKeyPressHandlers getTextBox(TextBoxType tbt) {
//		HasKeyPressHandlers tb = null;
//		switch (tbt){
//		case START: tb = startCityTextBox;  break;
//		case DESTINATION: tb = destinationCityTextBox;  break;
//
//		}
//		return tb;
		return null;
	}

	@Override
	public  HasSelectionHandlers<Suggestion> getSuggestion(MapView.TextBoxType tbt){
		return null;
	}

	@Override
	public HasClickHandlers getButton(ButtonType buttonType) {
		return searchCreateButtonMap.get(buttonType);
	}

	@Override
	public HasAllFocusHandlers getFocus(TextBoxType tbt) {
		return null;
	}



	@Override
	public HasClickHandlers getOKTimeButton() {
		return new Button();
		//return okButtonDepartureTime;
	}

	@Override
	public void updateDepartureTime() {
		int index = listBoxDestinationTime.getSelectedIndex();
		int value = timeValues[index];
		int hour = value/60;
		int min = value%60;
		TaxiGangInfo info = Session.getInstance().getSearchTaxiGangInfo();

		info.setDepartureHour(hour);
		info.setDepartureMinute(min);
		Date val = new Date();
		info.setDepartureDate(val.getDate(),val.getMonth(),val.getYear());
		info.setCreationTime(new Date());

	}

	@Override
	public void setMode(SearchDisplayMode mode) {
//		//		for (final TextBoxType textBoxType : TextBoxType.values()){
//		//			okButtonMap.get(textBoxType).setVisible(false);
//		//		}
//
//		switch (mode){
//		case START_CITY:
//			//startAddressSuggestion.setFocus(true);
//			setOKButtonVisible(TextBoxType.START_CITY, true);
//			break;
//		case START_ADDRESS:
//			startAddressLabel.setVisible(true);
//			startAddressTextBox.setVisible(true);
//			startAddressTextBox.setFocus(true);
//			setOKButtonVisible(TextBoxType.START_ADDRESS, true);
//			break;
//		case DESTINATION_CITY:
//			destinationCityLabel.setVisible(true);
//			destinationCityTextBox.setVisible(true);
//			//destinationCityTextBox.setValue(startCityTextBox.getValue());
//			destinationCityTextBox.setFocus(true);
//			setOKButtonVisible(TextBoxType.DESTINATION_CITY, true);
//			break;
//		case DESTINATION_ADDRESS:
//			destinationAddressLabel.setVisible(true);
//			destinationCityLabel.setVisible(true);
//			destinationCityTextBox.setVisible(true);
//			destinationAddressTextBox.setVisible(true);
//			destinationAddressTextBox.setFocus(true);
//			setOKButtonVisible(TextBoxType.DESTINATION_ADDRESS, true);
//			break;
//		case TIME:
//			departureLabel.setVisible(true);
//			listBoxDestinationTime.setVisible(true);
//			//			okButtonDepartureTime.setVisible(true);
//			break;
//		case SEARCH_CREATE:
//			//searchButtonPanel.setVisible(true);
//			//			okButtonDepartureTime.setVisible(false);
//			//						searchButton.setVisible(true);
//			//						searchButton.setFocus(true);
//			break;
//
//
//
//		}

	}

	@Override
	public void setStart(String start) {
		startSuggestion.getTextBox().setText(start);
	}

	@Override
	public void setDestination(String destination) {
		destinationSuggestion.getTextBox().setText(destination);
	}

	@Override
	public void setTextBoxText(TextBoxType tbt, String text) {
		Window.alert("TODO:setTextBoxText");

	}

	@Override
	public void setButtonMode(ButtonMode mode) {
		Window.alert("TODO:setButtonMode");

	}

	public String getSelectedTime() {
		// TODO Auto-generated method stub
		return null;
	}


	//sorry
	@UiField Button sorryCloseButton;
	@UiField Button sorryYesWishRouteButton;
	@UiField Label sorryText;
	@UiField
	Label sorryHeaderLabel;

	public void initSorry() {
		sorryText.setText(TaxiGangCreator.taxiGangConstants.noTaxiGangsFound());
		sorryYesWishRouteButton.setText(TaxiGangCreator.taxiGangConstants.yesPlease());
		sorryCloseButton.setText(TaxiGangCreator.taxiGangConstants.noThanks());
		sorryHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.sorry());

		sorryCloseButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				show(PanelType.SEARCH);
			}
		});

		sorryYesWishRouteButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname

				AsyncCallback<ConnectState> callback =  new AsyncCallback<ConnectState>() {

					@Override
					public void onFailure(Throwable caught) {
						Window.alert("error"+caught.getMessage());
					}

					@Override
					public void onSuccess(ConnectState result) {
						TaxiGangHandler.getInstance().createWishRoute();
						show(PanelType.SEARCH);
					}
				};

				FacebookApi.getEmail(callback);
			}
		});

	}

	//congratulations
	@UiField Button congratulationsContinueButton;

	@UiField Label congratulationsText;
	@UiField
	Label congratulationsHeaderLabel;

	public void initCongratulations() {
		congratulationsText.setText(TaxiGangCreator.taxiGangConstants.congratulationsCreate());
		congratulationsContinueButton.setText(TaxiGangCreator.taxiGangConstants.cont());
		congratulationsHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.congratulations());

		congratulationsContinueButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				show(PanelType.MYTAXIGANGS);
			}
		});

	}

	//congratulations
	@UiField Button congratulationsJoinContinueButton;

	@UiField Label congratulationsJoinText;
	@UiField
	Label congratulationsJoinHeaderLabel;

	public void initCongratulationsJoin() {
		congratulationsJoinText.setText(TaxiGangCreator.taxiGangConstants.congratulationsJoin());
		congratulationsJoinContinueButton.setText(TaxiGangCreator.taxiGangConstants.cont());
		congratulationsJoinHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.congratulations());

		congratulationsJoinContinueButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				show(PanelType.MYTAXIGANGS);
			}
		});

	}

	@UiField TextBox mobileNumberTextBox;
	//	
	@UiField
	Label mobileNumberHeaderLabel;

	@UiField
	Label enterMobileNumber;


	@UiField
	Button mobileNumberPreviousButton;

	@UiField
	Button mobileNumberContinueButton;


	public void initMobileNumber() {
		labelAreaCode.setText(TaxiGangCreator.taxiGangConstants.AreaCode());
		labelTelNo.setText(TaxiGangCreator.taxiGangConstants.TelNo());

		mobileNumberPreviousButton.setText(TaxiGangCreator.taxiGangConstants.back());
		mobileNumberHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.mobileNumber());

		enterMobileNumber.setText(TaxiGangCreator.taxiGangConstants.enterMobilenumber());
		mobileNumberContinueButton.setText(TaxiGangCreator.taxiGangConstants.cont());

		//setTaxiCompanyList("83333", listTaxiCompany);
		mobileNumberContinueButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				Session session = Session.getInstance();
				LoginInfo loginInfo = session.getLoginInfo();
				session.getLoginInfo().setMobilenumber(mobileNumberTextBox.getText());
				switch( session.getCreateJoin()){
				case CREATE:
					show(PanelType.CREATE_STEP1);
					break;
				case JOIN:
					TaxiGangInfo[] infoList = Session.getInstance().getTaxiGangSearchResultList();
					TaxiGangInfo taxiganginfo = infoList[Session.getInstance().getCurrentSuggestionIndex()];
					Session.getInstance().setJoinTaxiGangInfo(taxiganginfo);
					String message = TaxiGangCreator.taxiGangConstants.iJustJoined();
					ChitInfo chitInfo = new ChitInfo(message, new Date(), loginInfo.getNickname(), loginInfo.getMobilenumber());

					TaxiGangPresenter.getInstance().joinWithWait(chitInfo);
					break;

				}

			}
		});

		mobileNumberPreviousButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				show(PanelType.SEARCH);

			}
		});


	}


	public void initCreateStep1() {

		createStep1PreviousButton.setText(TaxiGangCreator.taxiGangConstants.back());
		willPhoneTaxiButton.setText(TaxiGangCreator.taxiGangConstants.iWillPhoneATaxi());
		willMeetAtTaxiRangButton.setText(TaxiGangCreator.taxiGangConstants.meetAtTaxiRang());
		createStep1HeaderLabel.setText(TaxiGangCreator.taxiGangConstants.step1());

		willPhoneTaxiButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				show(PanelType.CREATE_STEP2A);

			}
		});
		willMeetAtTaxiRangButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				show(PanelType.CREATE_STEP2B);

			}
		});

		createStep1PreviousButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				show(PanelType.MOBILENUMBER);

			}
		});


	}

	@UiField Button createStep1PreviousButton;

	@UiField
	Label createStep1HeaderLabel;

	@UiField
	Button willPhoneTaxiButton;

	@UiField
	Button willMeetAtTaxiRangButton;

	@UiField
	Button createStep2aContinueButton;



	//	//createStep2a
	@UiField
	Label enterTaxiNumber;
	//
	//
	////	@UiField
	////	TaxiCompanyCellTable taxiCompanyCellTable;
	//
	@UiField TextBox areaCodeTextBox;
	@UiField TextBox telNoTextBox;
	//	
	@UiField
	Label createStep2aHeaderLabel;
	@UiField
	Label labelAreaCode;
	@UiField
	Label labelTelNo;
	@UiField Button buttonTaxiCompany1;
	@UiField Button buttonTaxiCompany2;
	@UiField Button buttonTaxiCompany3;
	@UiField Button buttonTaxiCompany4;
	@UiField Button buttonTaxiCompany5;


	@UiField
	Button createStep2aPreviousButton;

	TaxiGangRoute.CreateMode createMode;

	public void initCreateStep2a() {
		labelAreaCode.setText(TaxiGangCreator.taxiGangConstants.AreaCode());
		labelTelNo.setText(TaxiGangCreator.taxiGangConstants.TelNo());

		createStep2aPreviousButton.setText(TaxiGangCreator.taxiGangConstants.back());
		createStep2aHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.step2());

		enterTaxiNumber.setText(TaxiGangCreator.taxiGangConstants.enterATaxiNumber());
		createStep2aContinueButton.setText(TaxiGangCreator.taxiGangConstants.cont());
		//setTaxiCompanyList("83333", listTaxiCompany);
		createStep2aContinueButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				String telNo = areaCodeTextBox.getText() + " " +telNoTextBox.getText();
				String meetingMessage = TaxiGangCreator.taxiGangConstants.iHaveCalledThisTaxi() + ":" + telNo;
				Session.getInstance().getSearchTaxiGangInfo().setMeetingMessage(meetingMessage);
				telNoLabel.setHref("tel:"+telNo);
				telNoLabel.setText(telNo);
				createMode = TaxiGangRoute.CreateMode.CALL_A_TAXI;
				show(PanelType.CREATE_STEP3);

			}
		});

		createStep2aPreviousButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				show(PanelType.CREATE_STEP1);

			}
		});


	}

	@UiField
	Button createStep2bContinueButton;

	@UiField
	Button createStep2bPreviousButton;

	@UiField
	Label createStep2bHeaderLabel;

	@UiField
	Label whereExactlyLabel;

	@UiField TextArea messageTextArea;


	public void initCreateStep2b() {
		createStep2bPreviousButton.setText(TaxiGangCreator.taxiGangConstants.back());

		createStep2bContinueButton.setText(TaxiGangCreator.taxiGangConstants.cont());
		createStep2bHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.step2());
		whereExactlyLabel.setText(TaxiGangCreator.taxiGangConstants.whereWillYouMeet());

		createStep2bContinueButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				createMode = TaxiGangRoute.CreateMode.MEET_AT_RANK;
				String message = messageTextArea.getText();
				Session.getInstance().getSearchTaxiGangInfo().setMeetingMessage(message);
				createTaxiGang();

			}

		});

		createStep2bPreviousButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				show(PanelType.CREATE_STEP1);

			}
		});

	}

	//create Step 3
	public void initCreateStep3() {
		createStep3PreviousButton.setText(TaxiGangCreator.taxiGangConstants.back());
		nowCallThisNumberLabel.setText(TaxiGangCreator.taxiGangConstants.nowCallAndOrderTaxi());
		createStep3ContinueButton.setText(TaxiGangCreator.taxiGangConstants.iHaveCalledThisTaxi());
		createStep3HeaderLabel.setText(TaxiGangCreator.taxiGangConstants.step3());

		createStep3ContinueButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				createTaxiGang();

			}
		});

		createStep3PreviousButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				if (createMode==CreateMode.CALL_A_TAXI)
					show(PanelType.CREATE_STEP2A);
				else
					show(PanelType.CREATE_STEP2B);

			}
		});

	}

	private void createTaxiGang(){
		//show(PanelType.CREATE_STEP4);		
		TaxiGangInfo info = Session.getInstance().getSearchTaxiGangInfo();
		LoginInfo loginInfo = Session.getInstance().getLoginInfo();
		String name = loginInfo.getNickname();
		ChitInfo chit = new ChitInfo(info.getMeetingMessage(), new Date(), name, loginInfo.getMobilenumber());
		TaxiGangPresenter.getInstance().createWithWait(chit);

	}

	@UiField Button createStep3ContinueButton;
	@UiField Button createStep3PreviousButton;
	@UiField Label nowCallThisNumberLabel;

	public static @UiField Anchor telNoLabel;
	@UiField Label createStep3HeaderLabel;

	//login panel

	@UiField public static com.google.gwt.user.client.ui.Button fbLoginButton;
	@UiField Button cancelLoginButton;
	@UiField Label fbLoginText;
	@UiField Label loginHeaderLabel;

	public void initLogin() {

		loginHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.sigin());
		fbLoginText.setText(TaxiGangCreator.taxiGangConstants.loginUseingFB());
		cancelLoginButton.setText(TaxiGangCreator.taxiGangConstants.cancel());
		cancelLoginButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				show(PanelType.SEARCH);
			}
		});

		//		fbLoginButton.addClickHandler(new ClickHandler() {
		//			
		//			@Override
		//			public void onClick(ClickEvent event) {
		//				// TODO store nickname
		//				
		//				Command command = new Command(){
		//					@Override
		//					public void execute(){
		//						Log.info("executing fbLogin");
		//						FacebookApi.mobilLogin(new LoginCallback());
		//					}
		//				};
		//				FacebookFactory.createFBConnection(null,command);
		//
		//				
		//				}
		//
		//		});

	}

	@UiField Button myTaxiGangsNextButton;
	@UiField Button myTaxiGangsPreviousButton;
	@UiField Button myTaxiGangsMessagesButton;
	@UiField Button myTaxiGangsDeleteButton;
	@UiField Button myTaxiGangsLeaveButton;
	@UiField Button myTaxiGangsCloseButton;
	@UiField Label myTaxiGangsStartAddressLabel;
	@UiField Label myTaxiGangsDestinationAddressLabel;
	@UiField Label myTaxiGangsJourneyBeginsLabel;
	@UiField Label myTaxiGangsLeaderLabel;
	//	@UiField Label myTaxiGangsMember1Label;
	//	@UiField Label myTaxiGangsMember2Label;
	//	@UiField Label myTaxiGangsMember3Label;

	@UiField Label myTaxiGangsStartAddressContentLabel;
	@UiField Label myTaxiGangsDestinationAddressContentLabel;
	@UiField Label myTaxiGangsJourneyBeginsContentLabel;

	@UiField Label myTaxiGangsLeaderContentLabel;
	@UiField FieldContain myTaxiGangsDetailField;
	//	@UiField Label myTaxiGangsMember1ContentLabel;
	//	@UiField Label myTaxiGangsMember2ContentLabel;
	//	@UiField Label myTaxiGangsMember3ContentLabel;
	@UiField Label myTaxiGangsHeaderLabel;


	public void initMyTaxiGangs() {
		myTaxiGangsHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.myTaxiGang());
		myTaxiGangsStartAddressLabel.setText(TaxiGangCreator.taxiGangConstants.startAddress());
		myTaxiGangsDestinationAddressLabel.setText(TaxiGangCreator.taxiGangConstants.enterDestinationAddress());
		myTaxiGangsJourneyBeginsLabel.setText(TaxiGangCreator.taxiGangConstants.departureTime());
		myTaxiGangsCloseButton.setText(TaxiGangCreator.taxiGangConstants.close());
		myTaxiGangsLeaderLabel.setText("Leader");
		//		myTaxiGangsMember1Label.setText("Member1");
		//		myTaxiGangsMember2Label.setText("Member2");
		//		myTaxiGangsMember3Label.setText("Member3");

		myTaxiGangsMessagesButton.setText(TaxiGangCreator.taxiGangConstants.messages());
		myTaxiGangsDeleteButton.setText(TaxiGangCreator.taxiGangConstants.delete());
		myTaxiGangsLeaveButton.setText(TaxiGangCreator.taxiGangConstants.leave());

		myTaxiGangsNextButton.setText(TaxiGangCreator.taxiGangConstants.next());
		myTaxiGangsPreviousButton.setText(TaxiGangCreator.taxiGangConstants.previous());

		myTaxiGangsMessagesButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				show(PanelType.MESSAGES);
			}
		});

		myTaxiGangsDeleteButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				TaxiGangInfo[] infoList = Session.getInstance().getMyTaxiGangList();
				Session session = Session.getInstance();
				if (infoList.length > session.getCurrentMyTaxiGangIndex()){
					TaxiGangInfo taxiganginfo = infoList[session.getCurrentMyTaxiGangIndex()];
					Session.getInstance().setCurrentMyTaxiGang(taxiganginfo);
					TaxiGangHandler.getInstance().deleteTaxiGang(false);
				} else {
					throw new RuntimeException(infoList.toString());
				}
			}
		});

		myTaxiGangsLeaveButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				TaxiGangInfo[] infoList = Session.getInstance().getMyTaxiGangList();
				Session session = Session.getInstance();
				if (infoList.length > session.getCurrentMyTaxiGangIndex()){
					TaxiGangInfo taxiganginfo = infoList[session.getCurrentMyTaxiGangIndex()];
					Session.getInstance().setCurrentMyTaxiGang(taxiganginfo);
					TaxiGangHandler.getInstance().leaveTaxiGang(false);
				} else {
					throw new RuntimeException(infoList.toString());
				}
			}
		});

		myTaxiGangsCloseButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				show(PanelType.SEARCH);
			}
		});

		myTaxiGangsNextButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				Session.getInstance().incCurrentMyTaxiGangIndex();
				showMyTaxiGangsContent();
			}

		});

		myTaxiGangsPreviousButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				Session.getInstance().decCurrentMyTaxiGangIndex();
				showMyTaxiGangsContent();
			}
		});

	}

	//private int currentTaxiGang = 0;

	//	public void show(){
	//		super.show();
	//
	//
	//		int length = Session.getInstance().getMyTaxiGangList().length;
	//		TaxiGangInfo[] infoList = Session.getInstance().getMyTaxiGangList();
	//		if (infoList.length > 0){
	//			TaxiGangInfo taxiganginfo = infoList[0];
	//			myTaxiGangsStartAddressContentLabel.setText(taxiganginfo.getStartAddress());
	//			myTaxiGangsDestinationAddressContentLabel.setText(taxiganginfo.getDestinationAddress());
	//			myTaxiGangsJourneyBeginsContentLabel.setText(TaxiGangHandler.formatter.format(taxiganginfo.getLocalDepartureTime()));
	//
	//			myTaxiGangsLeaderContentLabel.setText(taxiganginfo.getLeaderName());
	//			myTaxiGangsMember1ContentLabel.setText(taxiganginfo.getMemberName(0));
	//			myTaxiGangsMember2ContentLabel.setText(taxiganginfo.getMemberName(1));
	//			myTaxiGangsMember3ContentLabel.setText(taxiganginfo.getMemberName(2));
	//
	//			showMyTaxiGangInMap(taxiganginfo);
	//		}
	//
	//		myTaxiGangsNextButton.setVisible(currentTaxiGang>0);
	//		myTaxiGangsPreviousButton.setVisible(currentTaxiGang > 1);
	//
	//
	//	}

	@UiField Button newMessageButton;
	@UiField Button messagesCloseButton;
	@UiField Button messagesNextButton;
	@UiField Button messagesPreviousButton;

	@UiField Label messagesFromLabel;
	@UiField Label messagesFromContentLabel;
	@UiField Label messagesTimeLabel;
	@UiField Label messagesTimeContentLabel;
	@UiField Label messagesMobileNumberLabel;
	@UiField Label messagesMobileNumberContentLabel;
	@UiField Label messagesHeaderLabel;
	@UiField Label messagesTextLabel;
	@UiField Label messagesTextContentLabel;


	public void initMessages() {
		messagesHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.messages());
		newMessageButton.setText(TaxiGangCreator.taxiGangConstants.newMessage());
		messagesCloseButton.setText(TaxiGangCreator.taxiGangConstants.close());

		messagesNextButton.setText(TaxiGangCreator.taxiGangConstants.next());
		messagesPreviousButton.setText(TaxiGangCreator.taxiGangConstants.previous());
		newMessageButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				show(PanelType.NEW_MESSAGE);
			}
		});

		messagesCloseButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				show(PanelType.MYTAXIGANGS);
			}
		});

		messagesNextButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				messagesIndex++;
				showMessagesContent();
			}
		});

		messagesPreviousButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				messagesIndex--;
				showMessagesContent();
			}
		});

	}



	@Override
	public void resetSuggestion() {
		MobileNavigatorManager.resetSuggestion(this);

	}

	@Override
	public void createStartMarker(String start, boolean setAddress) {
		MobileNavigatorManager.createStartMarker(start, this);

	}

	@Override
	public void createDestinationMarker(String destination, boolean setAddress) {
		MobileNavigatorManager.createDestinationMarker(destination, this);

	}
	@Override
	public void createStartDestinationMarker(String start, String dest, boolean setAddress) {
		MobileNavigatorManager.createStartDestinationMarker(start, dest, this);

	}

	@Override
	public void showSuggestionInMap(TaxiGangInfo suggestion) {
		suggestionMapButton.setActive(false);
		MobileNavigatorManager.createSuggestion(suggestion,this);
		suggestionMapButton.setActive(true);
	}

	@Override
	public void showMap() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setLoggedOut(String msg) {
		show(PanelType.LOGIN);

	}

	@Override
	public void setLoggedIn(Provider provider) {
		show(panelToShowAtShowLogin);

	}

	@Override
	public void setFeedbackButtonVisible(boolean b) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setLoginButtonVisible(boolean b) {
		// TODO Auto-generated method stub

	}

	@Override
	public void showGuide() {
		// TODO Auto-generated method stub

	}

	@Override
	public void hideGuide() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setStartCity() {
		// TODO Auto-generated method stub

	}

	private int messagesIndex;
	@Override
	public void show(PanelType panelType) {
		if (TaxigangMode.TAXIGANG == Session.getInstance().getMode() && panelType == PanelType.SEARCH){
			panelType = PanelType.SUGGESTION;
		}
		panelToShowAtShowLogin = PanelType.SEARCH; //reset
		for (Panel panel : taxiGangPanels.values()){
			panel.setVisible(false);
		}
		ProcessingDialog.hide();

		Log.info("show "+panelType);
		Panel p = taxiGangPanels.get(panelType);
		p.setVisible(true);

		menuButton.setVisible(false);
		suggestionMapButton.setVisible(false);
		myTaxiGangsMapButton.setVisible(false);
		closeMapButton.setVisible(false);

		switch (panelType){
		case  SEARCH:
			menuButton.setVisible(true);

			break;
		case  LOGIN:

			break;

		case  MYTAXIGANGS:
			showingMyTaxiGangs = true; 
			showMyTaxiGangsContent();
			myTaxiGangsMapButton.setVisible(true);
			break;

		case  MESSAGES:

			showMessagesContent();


			break;
		case  MAP:

			closeMapButton.setVisible(true);
			break;

		case SUGGESTION:

			showingMyTaxiGangs = false; 
			suggestionMapButton.setVisible(true);

			TaxiGangInfo[] suggestionsInfoList = Session.getInstance().getTaxiGangSearchResultList();
			if (suggestionsInfoList!=null){
			int currentSuggestionIndex = Session.getInstance().getCurrentSuggestionIndex();

			if (suggestionsInfoList.length > 0){

				if (suggestionsInfoList.length==1){
					suggestionsHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.suggestion());
				} else {
					int displayIndex = Session.getInstance().getCurrentSuggestionIndex()+1;
					suggestionsHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.suggestions()+" "+displayIndex+" of "+suggestionsInfoList.length);
				}

				TaxiGangInfo currentTaxigangSuggestion = suggestionsInfoList[currentSuggestionIndex];
				suggestionsStartAddressContentLabel.setText(currentTaxigangSuggestion.getStart());
				suggestionsDestinationAddressContentLabel.setText(currentTaxigangSuggestion.getDestination());
				suggestionsJourneyBeginsContentLabel.setText(currentTaxigangSuggestion.getDepartureTime());

				boolean closed = "CLOSED".equals(currentTaxigangSuggestion.getStatus());
				if (closed){
					suggestionsHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.taxigangHasExpired());
				} 
				suggestionsJoinButton.setEnabled(!closed);
			}

			suggestionsNextButton.setVisible( suggestionsInfoList.length - currentSuggestionIndex > 1);
			suggestionsPreviousButton.setVisible(currentSuggestionIndex > 0);
			}
			break;
		case CREATE_STEP2A:
			TaxiGangInfo taxiGangInfo = Session.getInstance().getSearchTaxiGangInfo();
			TaxiGangHandler.getInstance().getTaxiCompany(taxiGangInfo);
			break;


		}

	}
	private void showMyTaxiGangsContent() {
		int length = Session.getInstance().getMyTaxiGangList().length;
		TaxiGangInfo[] myTaxiGangsInfoList = Session.getInstance().getMyTaxiGangList();
		int currentMyTaxiGangIndex = Session.getInstance().getCurrentMyTaxiGangIndex();
		if (myTaxiGangsInfoList.length > 0){
			if (myTaxiGangsInfoList.length==1){
				myTaxiGangsHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.myTaxiGang());
			} else {

				int displayIndex = currentMyTaxiGangIndex+1;
				myTaxiGangsHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.myTaxiGang()+" "+displayIndex+" of "+myTaxiGangsInfoList.length);

			}
			TaxiGangInfo taxiganginfo = myTaxiGangsInfoList[currentMyTaxiGangIndex];
			myTaxiGangsStartAddressContentLabel.setText(taxiganginfo.getStart());
			myTaxiGangsDestinationAddressContentLabel.setText(taxiganginfo.getDestination());
			myTaxiGangsJourneyBeginsContentLabel.setText(taxiganginfo.getDepartureTime());

			myTaxiGangsLeaderContentLabel.setText(taxiganginfo.getLeaderName());
			myTaxiGangsDetailField.clear();
			int size = taxiganginfo.getMember().length;
			for (int i=0; i < taxiganginfo.getMember().length-1; i++){
				//				<!--g:HorizontalPanel>
				//				<g:Label ui:field="myTaxiGangsMember1Label" width="100px"></g:Label>
				//				<g:Label ui:field="myTaxiGangsMember1ContentLabel"></g:Label>
				//			</g:HorizontalPanel>
				HorizontalPanel panel = new HorizontalPanel();
				Label l1 = new Label("Member"+(i+1));
				l1.setWidth("100px");
				Label l2 = new Label(taxiganginfo.getMemberName(i));
				panel.add(l1);
				panel.add(l2);
				myTaxiGangsDetailField.add(panel);

			}
			//			myTaxiGangsMember1ContentLabel.setText(taxiganginfo.getMemberName(0));
			//			myTaxiGangsMember2ContentLabel.setText(taxiganginfo.getMemberName(1));
			//			myTaxiGangsMember3ContentLabel.setText(taxiganginfo.getMemberName(2));

		}

		myTaxiGangsNextButton.setVisible( myTaxiGangsInfoList.length - currentMyTaxiGangIndex > 1);
		myTaxiGangsPreviousButton.setVisible(currentMyTaxiGangIndex > 0);

		int noMembers = Session.getInstance().getCurrentMyTaxiGang().getNumMembers();
		Log.info("no members="+noMembers);
		myTaxiGangsLeaveButton.setVisible(noMembers > 0);
		myTaxiGangsDeleteButton.setVisible(noMembers == 0);

	}

	private void showMessagesContent(){
		TaxiGangInfo taxiGangInfo = Session.getInstance().getCurrentMyTaxiGang();
		ChitInfo[] chitList = taxiGangInfo.getChitList();
		if (messagesIndex < chitList.length){
			ChitInfo chitInfo = chitList[messagesIndex];

			int numChits = taxiGangInfo.getChitList().length;
			messagesNextButton.setVisible(messagesIndex < numChits-1);		
			messagesPreviousButton.setVisible(messagesIndex != 0);

			messagesFromLabel.setText(TaxiGangCreator.taxiGangConstants.from());
			messagesFromContentLabel.setText(chitInfo.getAuthorName());
			messagesTimeLabel.setText(TaxiGangCreator.taxiGangConstants.time());
			messagesTimeContentLabel.setText(TaxiGangHandler.formatter.format(chitInfo.getDate()));
			messagesMobileNumberLabel.setText(TaxiGangCreator.taxiGangConstants.mobileNumber());
			messagesMobileNumberContentLabel.setText(Session.getInstance().getLoginInfo().getMobilenumber());
			messagesTextLabel.setText(TaxiGangCreator.taxiGangConstants.messages());
			messagesTextContentLabel.setText(chitInfo.getChitText());
		} else {
			throw new RuntimeException("Messages: out of bounds:index"+messagesIndex+":chitlength"+chitList.length);
		}

	}

	@UiField Button suggestionsNextButton;
	@UiField Button suggestionsPreviousButton;
	@UiField Button suggestionsJoinButton;
	@UiField Button suggestionsCloseButton;
	@UiField Label suggestionsStartAddressLabel;
	@UiField Label suggestionsDestinationAddressLabel;
	@UiField Label suggestionsJourneyBeginsLabel;

	@UiField Label suggestionsStartAddressContentLabel;
	@UiField Label suggestionsDestinationAddressContentLabel;
	@UiField Label suggestionsJourneyBeginsContentLabel;
	@UiField Label suggestionsHeaderLabel;


	public void initSuggestion() {
		suggestionsHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.suggestion());
		suggestionsStartAddressLabel.setText(TaxiGangCreator.taxiGangConstants.startAddress());
		suggestionsDestinationAddressLabel.setText(TaxiGangCreator.taxiGangConstants.enterDestinationAddress());
		suggestionsJourneyBeginsLabel.setText(TaxiGangCreator.taxiGangConstants.departureTime());
		suggestionsCloseButton.setText(TaxiGangCreator.taxiGangConstants.close());

		suggestionsJoinButton.setText(TaxiGangCreator.taxiGangConstants.join());

		suggestionsNextButton.setText(TaxiGangCreator.taxiGangConstants.next());
		suggestionsPreviousButton.setText(TaxiGangCreator.taxiGangConstants.previous());


		suggestionsCloseButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				Session.getInstance().setMode(null);
				Session.getInstance().setRef(null);
				resetSuggestion();
				show(PanelType.SEARCH);
			}
		});

		suggestionsNextButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				Session session = Session.getInstance();
				int currentSuggestion = session.getCurrentSuggestionIndex();
				Log.info("currentSuggestionIndex="+currentSuggestion);
				currentSuggestion++;
				session.setCurrentSuggestionIndex(currentSuggestion);

				show(PanelType.SUGGESTION);
			}
		});

		suggestionsPreviousButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				Session session = Session.getInstance();
				int currentSuggestion = session.getCurrentSuggestionIndex();
				currentSuggestion--;
				session.setCurrentSuggestionIndex(currentSuggestion);
				show(PanelType.SUGGESTION);
			}
		});

	}

	//private int suggestionsCurrentTaxiGang = 0;


	public void initNewMessage() {
		newMessageSendButton.setText(TaxiGangCreator.taxiGangConstants.sendMessage());
		newMessageCancelButton.setText(TaxiGangCreator.taxiGangConstants.cancel());
		newMessageHeaderLabel.setText(TaxiGangCreator.taxiGangConstants.newMessage());

		newMessageSendButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				TaxiGangInfo taxiganginfo = Session.getInstance().getCurrentMyTaxiGang();
				TaxiGangHandler.getInstance().addMessage(taxiganginfo, newMessageTextArea.getText());
			}
		});

		newMessageCancelButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO store nickname
				show(PanelType.MESSAGES);
			}
		});
	}

	public void initOrderTaxiCompany(){
		
	}
	@UiField Button newMessageSendButton;
	@UiField Button newMessageCancelButton;
	@UiField TextArea newMessageTextArea;
	@UiField
	Label newMessageHeaderLabel;




	@Override
	public SearchView getSearchView() {
		return this;
	}


	@Override
	public void showMyTaxiGangInMap(TaxiGangInfo taxigang, boolean setAddress) {
		MobileNavigatorManager.createSuggestion(taxigang, this);
		//		MobileNavigatorManager.staticStartAddress = taxigang.getStartAddress();
		//		MobileNavigatorManager.staticDestinationAddress = taxigang.getDestinationAddress();

		//		String startAddress = taxigang.getStartAddress();
		//		if (startAddress != null){
		//			MobileNavigatorManager.createStartMarker(taxigang.getStartAddress(),this);
		//		}
		//		String destinationAddress = taxigang.getDestinationAddress();
		//
		//		if (destinationAddress != null){
		//			MobileNavigatorManager.createDestinationMarker(destinationAddress,this);
		//		}

	}

	@Override
	public void show() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setPanelToShowOnLogin(PanelType panelType) {
		this.panelToShowAtShowLogin = panelType;
	}

//	@Override
//	public void initOracle() {
//		Session session = Session.getInstance();
//		if (session != null && session.getTaxiGangUserInfo() != null){
//
//			MultiWordSuggestOracle startCityOracle = (MultiWordSuggestOracle)startCitySuggestion.getSuggestOracle();  
//			MultiWordSuggestOracle startAddressOracle = (MultiWordSuggestOracle)startAddressSuggestion.getSuggestOracle();  
//			MultiWordSuggestOracle destCityOracle = (MultiWordSuggestOracle)destinationCitySuggestion.getSuggestOracle();  
//			MultiWordSuggestOracle destAddressOracle = (MultiWordSuggestOracle)destinationAddressSuggestion.getSuggestOracle();  
//
//			String[] cityList = session.getTaxiGangUserInfo().getCityList();
//			for (String suggestion : cityList){
//				startCityOracle.add(suggestion);	
//				destCityOracle.add(suggestion);	
//			}
//			if (cityList.length > 0){
//
////				session.getSearchTaxiGangInfo().setStartCity(cityList[0]);
////				session.getSearchTaxiGangInfo().setDestinationCity(cityList[0]);
////				startCitySuggestion.setText(cityList[0]);
////				destinationCitySuggestion.setText(cityList[0]);
//				//setMode(SearchDisplayMode.START_ADDRESS);
//				//				if (presenter != null ){
//				//					presenter.showStartAddress(cityList[0]);
//				//				}
//			}
//			String[] addressList = session.getTaxiGangUserInfo().getAddressList();
//			for (String suggestion : addressList){
//				startAddressOracle.add(suggestion);	
//				destAddressOracle.add(suggestion);	
//			}
//		}
//
//	}


	@Override
	public void showLoginButton(boolean show) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void displayTaxiCompanyList(TaxiCompanyInfo[] listTaxiCompanies) {
		Button[]step2ATaxiCompanyButtons = new Button[]{buttonTaxiCompany1,buttonTaxiCompany2,buttonTaxiCompany3,buttonTaxiCompany4,buttonTaxiCompany5};
		for (Button b: step2ATaxiCompanyButtons){
			b.setVisible(false);
		}
		int row = 0;
		final HashMap<String,TaxiCompanyInfo>mapTaxiCompanyInfo = new HashMap<String,TaxiCompanyInfo>();
		for (TaxiCompanyInfo taxiCompanyInfo : listTaxiCompanies){
			String name = taxiCompanyInfo.getName();
			mapTaxiCompanyInfo.put(name,taxiCompanyInfo);
			Button b = step2ATaxiCompanyButtons[row];
			b.setText(name);
			b.setTitle(name);
			b.setVisible(true);
			b.addClickHandler(new ClickHandler() {
				
				@Override
				public void onClick(ClickEvent event) {
					Object objSrc = event.getSource();
					Button b = (Button)objSrc;
					String name = b.getTitle();
					TaxiCompanyInfo taxiCompanyInfo = mapTaxiCompanyInfo.get(name);
					if (taxiCompanyInfo.getUrl() != null){
						Command cmd = new Command(){

							@Override
							public void execute() {
								taxiGangMobile.createTaxiGang();								
							}							
						};
						//Window.alert(taxiCompanyInfo.getUrl());
						TaxiCompanyDialog.show(taxiCompanyInfo,cmd);
					}else{
						areaCodeTextBox.setText(taxiCompanyInfo.getTelAreaCode());
						telNoTextBox.setText(taxiCompanyInfo.getTelNo());
					}
				}
			});
			row++;
		}
		
	}
	TaxiGangMobile taxiGangMobile;






}
